﻿using UnityEngine;
using System.Collections;


public delegate void OnCallBack();
public class BlackScreen : MonoBehaviour {
    public TweenAlpha tween;
    public bool isShowing = false;
    private static BlackScreen _instance;
    public static BlackScreen Instance 
    {
        get { return _instance; }
    }

    public void ShowBlack(OnCallBack onShow) 
    {
        tween.gameObject.SetActive(true);
        tween.ResetToBeginning();
        tween.PlayForward();
        isShowing = true;
        if (onShow != null)
        {
            StartCoroutine(ShowBlackCallBack(onShow));
        }
    }
    private IEnumerator ShowBlackCallBack(OnCallBack onShow) {
        yield return new WaitForSeconds(tween.duration);
        if (onShow != null)
            onShow();
    }
    public void HideBlack(OnCallBack onHide) {
        tween.gameObject.SetActive(true);
        tween.PlayReverse();
        if (onHide != null)
        {
            StartCoroutine(HideBlackCallBack(onHide));
        }
    }
    private IEnumerator HideBlackCallBack(OnCallBack onHide) {
        yield return new WaitForSeconds(tween.duration);
        if (onHide != null)
            onHide();
        tween.gameObject.SetActive(false);
        isShowing = false;
    }
    void Awake() 
    { 
        _instance = this; 
    }
}
